#include <bits/stdc++.h>

using namespace std;

class Solution {
   public:
    vector<int> distinctDifferenceArray(vector<int>& nums) {
        vector<int> ans;
        vector<int> f(ans.size(), 0), l(ans.size(), 0);
        set<int> s;
        for (int i = 0; i < nums.size(); ++i) {
            s.insert(nums[i]);
            f[i] = s.size();
        }
        s.clear();
        for (int i = nums.size() - 1; i >= 0; --i) {
            s.insert(nums[i]);
            l[i] = s.size();
        }
        for (int i = 0; i < nums.size(); ++i) {
            ans[i] = f[i] - l[i];
        }
        return ans;
    }
};